package cc.yugu.yhdw.common.protocol.msg02;

import cc.yugu.yhdw.common.protocol.MsgCode;
import cc.yugu.yhdw.common.tool.netty.TypeOperator;
import io.netty.buffer.ByteBuf;

import java.util.ArrayList;
import java.util.List;

/**
 * 终端登录(响应)
 */
public class Msg022000001 extends Msg022 {

    public String cabinetId;
    public String cabinetName;
    public String strategyUid;
    public List<Property> propertyList = new ArrayList<Property>();
    public byte fst;
    public byte fot;
    public byte pt;
    public byte rpt;
    public List<Box> BoxList = new ArrayList<Box>();

    @Override
    public int getMsgCode() {
        return MsgCode.MSG_022000001.getCode();
    }

    @Override
    public void writeData(ByteBuf buffer) {
        writeRtn(buffer);
        writeString(buffer, cabinetId);
        writeString(buffer, cabinetName);
        writeString(buffer, strategyUid);

        buffer.writeInt(propertyList.size());
        for(Property property : propertyList) {
            property.write(buffer);
        }

        buffer.writeByte(fst);
        buffer.writeByte(fot);
        buffer.writeByte(pt);
        buffer.writeByte(rpt);
        buffer.writeInt(BoxList.size());
        for (Box e : BoxList) {
            e.write(buffer);
        }
    }

    public static class Box extends TypeOperator {
        public String boxNum;
        public byte boxStatus;

        public Box(String boxNum, byte boxStatus) {
            this.boxNum = boxNum;
            this.boxStatus = boxStatus;
        }

        public void write(ByteBuf buffer) {
            writeString(buffer, boxNum);
            buffer.writeByte(boxStatus);
        }

        public void read(ByteBuf buffer) {
            boxNum = readString(buffer);
            boxStatus = buffer.readByte();
        }
    }

    public static class Property extends TypeOperator {
        public String name;
        public String value;

        public Property(String name, String value) {
            this.name = name;
            this.value = value;
        }

        public void write(ByteBuf buffer) {
            writeString(buffer, name);
            writeString(buffer, value);
        }
    }
}
